//
//  SSBaseTableViewController.swift
//  weibooo
//
//  Created by  sulcan on 16/4/8.
//  Copyright © 2016年 苏烁. All rights reserved.
//

import UIKit

class SSBaseTableViewController: UITableViewController {

    var userLogin: Bool = false
    
    override func loadView() {
        userLogin ? super.loadView() : setupVisitorView()
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Uncomment the following line to preserve selection between presentations
        // self.clearsSelectionOnViewWillAppear = false

        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        // self.navigationItem.rightBarButtonItem = self.editButtonItem()
    }

    // setupVisitorView
    func setupVisitorView() {
        view = visitorView
        
        // 成为访客视图的代理
        visitorView.delegate = self
        
        // 通过判断当前控制器的类型，更改控制器的view要显示的内容
        if self is SSHomeViewController {
            visitorView.startRotation()
        }else if self is SSMessageViewController {
            visitorView.setupVisitorViewInfo(imageName: "visitordiscover_image_message", message: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
        }else if self is SSDiscoverViewController {
            visitorView.setupVisitorViewInfo(imageName: "visitordiscover_image_message", message: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
        }else if self is SSProfileViewController {
            visitorView.setupVisitorViewInfo(imageName: "visitordiscover_image_profile", message: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
        }
        
        // 设置导航栏按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: Selector("visitorViewDidClickRegisterButton"))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", style: UIBarButtonItemStyle.Plain, target: self, action: Selector("visitorViewDidClickLoginButton"))
        
    }
    
    // 导航栏按钮回调
//    @objc private func didClickRegister() {
//        print("didClickRegister")
//    }
//    @objc private func didClickLogin() {
//        print("didClickLogin")
//    }
    
    
    
    // mark: - 懒加载
    lazy var visitorView:SSVisitorView = SSVisitorView()
    
    
    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 0
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return 0
    }

}

// 扩展和OC的分类很像，只能扩展方法，可以让对象实现协议，方便管理代码
extension SSBaseTableViewController: SSVisitorViewDelegate{
    // visitorView代理方法
    // 实现协议中的方法，对于require不实现还是会报错
    func visitorViewDidClickLoginButton() {
        SSPrint("visitorViewDidClickLoginButton")
    }
    
    func visitorViewDidClickRegisterButton() {
        SSPrint("visitorViewDidClickRegisterButton")
    }
}
